using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class ValuecodeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public ValuecodeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.User;
						tableVersionTypes[HL7Version.v231] = HL7TableType.User;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{""};
						validVersionCodes[HL7Version.v231] = new string[]{"01","02","04","05","06","08","09","10","11","12","13","14","15","16","17","21","22","23","24","30","31","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","56","57","58","59","60","67","68","70 ... 72","75 ... 79","80","81","A1","A2","A3","X0","X4"};
						validVersionCodes[HL7Version.v24] = new string[]{"01","02","04","05","06","08","09","10","11","12","13","14","15","16","17","21","22","23","24","30","31","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","56","57","58","59","60","67","68","70 ... 72","75 ... 79","80","81","A1","A2","A3","X0","X4"};
						validVersionCodes[HL7Version.v25] = new string[]{""};
						validVersionCodes[HL7Version.v251] = new string[]{"..."};
						validVersionCodes[HL7Version.v26] = new string[]{"..."};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{""};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Most common semi-private rate","Hospital has no semi-private rooms","Inpatient professional component charges which are combined billed","Professional component included in charges and also billed separate to carrier","Medicare blood deductible","Medicare life time reserve amount in the first calendar year","Medicare co-insurance amount in the first calendar year","Lifetime reserve amount in the second calendar year","Co-insurance amount in the second calendar year","Working aged beneficiary/spouse with employer group health plan","ESRD beneficiary in a Medicare coordination period with an employer group health plan","No Fault including auto/other","Worker’s Compensation","PHS, or other federal agency","Payer code","Catastrophic","Surplus","Recurring monthly incode","Medicaid rate code","Pre-admission testing","Patient liability amount","Pints of blood furnished","Blood deductible pints","Pints of blood replaced","New coverage not implemented by HMO (for inpatient service only)","Black lung","VA","Disabled beneficiary under age 64 with LGHP","Amount provider agreed to accept from primary payer when this amount is less than charges but higher than payment received,, then a Medicare secondary payment is due","Accident hour","Number of grace days","Any liability insurance","Hemoglobin reading","Hematocrit reading","Physical therapy visits","Occupational therapy visits","Speech therapy visits","Cardiac rehab visits","Skilled nurse - home visit hours","Home health aide - home visit hours","Arterial blood gas","Oxygen saturation","HHA branch MSA","Peritoneal dialysis","EPO-drug","Payer codes","Payer codes","Psychiatric visits","Visits subject to co-payment","Deductible payer A","Coinsurance payer A","Estimated responsibility payer A","Service excluded on primary policy","Supplemental coverage"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Most common semi-private rate","Hospital has no semi-private rooms","Inpatient professional component charges which are combined billed","Professional component included in charges and also billed separate to carrier","Medicare blood deductible","Medicare life time reserve amount in the first calendar year","Medicare co-insurance amount in the first calendar year","Lifetime reserve amount in the second calendar year","Co-insurance amount in the second calendar year","Working aged beneficiary/spouse with employer group health plan","ESRD beneficiary in a Medicare coordination period with an employer group health plan","No Fault including auto/other","Worker's Compensation","PHS, or other federal agency","Payer code","Catastrophic","Surplus","Recurring monthly incode","Medicaid rate code","Pre-admission testing","Patient liability amount","Pints of blood furnished","Blood deductible pints","Pints of blood replaced","New coverage not implemented by HMO (for inpatient service only)","Black lung","VA","Disabled beneficiary under age 64 with LGHP","Amount provider agreed to accept from primary payer when this amount is less than charges but higher than payment received,, then a Medicare secondary payment is due","Accident hour","Number of grace days","Any liability insurance","Hemoglobin reading","Hematocrit reading","Physical therapy visits","Occupational therapy visits","Speech therapy visits","Cardiac rehab visits","Skilled nurse - home visit hours","Home health aide - home visit hours","Arterial blood gas","Oxygen saturation","HHA branch MSA","Peritoneal dialysis","EPO-drug","Payer codes","Payer codes","Psychiatric visits","Visits subject to co-payment","Deductible payer A","Coinsurance payer A","Estimated responsibility payer A","Service excluded on primary policy","Supplemental coverage"};
						validVersionDescriptions[HL7Version.v25] = new string[]{""};
						validVersionDescriptions[HL7Version.v251] = new string[]{"See NUBC codes"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"See NUBC codes"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
